package org.feng.clog;

import org.feng.clog.utils.StringUtil;
import org.slf4j.MDC;

/**
 * 日志ID
 *
 * @author feng
 */
public class LogId {
    private static final String KEY_MDC = "logId";

    private LogId() {
    }

    public static void put(String logId) {
        MDC.put(KEY_MDC, logId);
    }

    public static String get() {
        String logId = MDC.get(KEY_MDC);
        if (logId == null) {
            logId = StringUtil.uuid();
            put(logId);
        }

        return logId;
    }

    public static void remove() {
        MDC.remove(KEY_MDC);
    }
}
